/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facades;

import entities.Language;
import java.util.List;
import java.util.Locale;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author damfercer
 */
@Stateless
public class LanguageFacade extends AbstractFacade<Language> {
    @PersistenceContext(unitName = "ProyectoPU")
    private EntityManager em;
    private final Integer idEnglish=1;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public LanguageFacade() {
        super(Language.class);
    }
    public Language find(String code){
        Language res = null;
        Query q =em.createNamedQuery("Language.findByCode");
        List<Language> list=q.setParameter("code", code).getResultList();
        if(list!=null && !list.isEmpty()){
            res=list.get(0);
        }
        return res;
    }
    public Language find(Locale locale){
        return find(locale.getLanguage());
    }

    public Language getEnglish() {
        return find(idEnglish);
    }
    
}
